<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 计算属性简写只能访问,不能修改
        如何要 "修改" -> 需要写计算属性的完整写法.
        简写:
        computed: {
            一段代码逻辑
            return 结果
        }

        完整写法:
        computed: {
            get (){
                一段代码逻辑
                return 结果
            },
            set (修改的值){
                一段代码逻辑
                return 结果
            }
        }
    
    -->
    <div id="app">
        姓：<input v-model="firstName" type="text"><br>
        名：<input v-model="lastName" type="text"><br>
        <p>姓名：{{ fullName }}</p>
        <button v-on:click="changeName">修改姓名</button>
      </div>
    <script src="./vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                firstName: '刘',
                lastName: '备'
            },
            methods: {
                changeName () {
                    this.fullName = "吕小布"
                }
            },
            computed: {
                // 当fullName被修改赋值时,会自动执行set,修改的值,会传递给set方法
                fullName: {
                    get (){
                        return this.firstName + this.lastName
                    },
                    set (value){
                        this.firstName = value.slice(0, 1)
                        this.lastName = value.slice(1)
                    }
                }
            }
        })
    </script>
</body>
</html>